package org.training.person.mason.basic.keyword;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.logging.Logger;

public class ClassInvoke {
	private static final Logger LOGGER = Logger.getLogger(ClassInvoke.class.getName());
	/**
	 * This method used to get all the method of the class.
	 * @param className
	 * @return
	 */
	public Method[] getMethods(String className){
		LOGGER.info("get methods of Class "+ className);
		Method[] methods = null;
		try {			
			Class<?> c = Class.forName(className);
			methods = c.getDeclaredMethods();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		LOGGER.info("there are "+methods.length+ " methods of Class "+ className);
		return methods;
	}
	
	/**
	 * This method used to get all the field of the class.
	 * @param className
	 * @return
	 */
	public Field[] getFields(String className){
		LOGGER.info("get fileds of Class " + className);
		Field[] fields = null;
		
		try {
			Class<?> c = Class.forName(className);
			fields = c.getDeclaredFields();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		LOGGER.info("there are "+fields.length+ " fields of Class "+ className);
		return fields;
	}
	
	public static void main(String... args){
		ClassInvoke ci = new ClassInvoke();
		String className = Character.class.getCanonicalName();
		LOGGER.info("ClassName is "+className);
		Method[] methods = ci.getMethods(className);
		Field[] fields = ci.getFields(className);
		for (Field field : fields) {
			LOGGER.info(field.toString());
		}
		for (Method method : methods) {
			LOGGER.info(method.toString() +method.getReturnType());
			
		}
		
		System.out.println(Double.SIZE);
	}
}
